﻿using System;
using System.Text;
using DotRas;
using System.Net.NetworkInformation;

namespace TrafficSplitter
{
    class VirtualAdapter
    {
        private String EntryName;
        private TS_ADAPTER_TYPES DeviceType;
        private Int32 DeviceID;
        private UInt32 Metric;
        private UInt32 Index;
        private RasHandle Handle;
        private String Gateway;
        private String IPAddress;
        private NetworkInterface NetworkInterface;

        public VirtualAdapter(String entryName, UInt32 index, TS_ADAPTER_TYPES deviceType, Int32 deviceID)
        {
            this.EntryName = entryName;
            this.DeviceType = deviceType;
            this.DeviceID = deviceID;
            this.Handle = null;
            this.Metric = 0;
            this.Index = index;
            this.Gateway = null;
            this.IPAddress = null;
            this.NetworkInterface = null;
        }

        public void SetNetworkInterface(NetworkInterface netInterface)
        {
            this.NetworkInterface = netInterface;
        }

        public NetworkInterface GetNetworkInterface()
        {
            return this.NetworkInterface;
        }

        public IPInterfaceProperties GetInterfaceProperties()
        {
            return this.NetworkInterface.GetIPProperties();
        }

        public void SetHandle(RasHandle handle)
        {
            this.Handle = handle;
        }

        public RasHandle GetHandle()
        {
            return this.Handle;
        }

        public String GetEntryName()
        {
            return this.EntryName;
        }

        public TS_ADAPTER_TYPES GetDeviceType()
        {
            return this.DeviceType;
        }

        public Int32 GetDeviceID()
        {
            return this.DeviceID;
        }

        public UInt32 GetIndex()
        {
            return this.Index;
        }

        public void SetIndex(UInt32 index)
        {
            this.Index = index;
        }

        public void SetIndex(int index)
        {
            SetIndex((UInt32)index);
        }

        public UInt32 GetMetric()
        {
            return this.Metric;
        }

        public void SetMetric(UInt32 metric)
        {
            this.Metric = metric;
        }

        public String GetGateway()
        {
            return this.Gateway;
        }

        public void SetGateway(String gateway)
        {
            this.Gateway = gateway;
        }

        public String GetIPAddress()
        {
            return this.IPAddress;
        }

        public void SetIPAddress(String ipAddress)
        {
            this.IPAddress = ipAddress;
        }

        public override string ToString()
        {
            return this.EntryName;
        }

        public override bool Equals(object obj)
        {
            if ((obj is DBNull) || (obj == null))
                return false;
            else if (obj is String)
            {
                return (String.Compare(((String)obj).Trim(), this.EntryName.Trim(), true) == 0);
            }
            else
            {
                return (String.Compare(((VirtualAdapter)obj).GetEntryName().Trim(), this.EntryName.Trim(), true) == 0);
            }
        }

        public override int GetHashCode()
        {
            return this.EntryName.GetHashCode();
        }
    }
}
